#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>
#include "ZQ_CPP_LIB/time_cost.hpp"


int main(int argc, char** argv){
  int msg_len = 1024;
  int msg_cnt = 10000000;
  int client_sockfd;
  int len;
  struct sockaddr_in remote_addr;
  char buf[BUFSIZ];
  memset(&remote_addr, 0, sizeof(remote_addr));
  remote_addr.sin_family = AF_INET;
  remote_addr.sin_addr.s_addr = inet_addr("192.168.2.48");
  remote_addr.sin_port = htons(8000);

  if ((client_sockfd = socket(PF_INET, SOCK_STREAM, 0)) <0){
    perror("socket error");
    return 1;
  };

  if(connect(client_sockfd, (struct sockaddr*)&remote_addr, sizeof(struct sockaddr))<0){
    perror("connect error");
    return 1;
  };

  printf("connected to server\n");
  zq_cpp_lib::get_start_time();
  for (auto i = 1; i <= msg_cnt; i++){
    for (auto sent = 0; sent<msg_len;){
      sent+=send(client_sockfd, buf, msg_len-sent,0);
    };
    if (i%(msg_cnt/100)==0){
      printf("i=%d\n",i);
    };
  };
  zq_cpp_lib::get_end_time();
  printf("cost time: %lf(ms)", zq_cpp_lib::get_cost_time_by_ms());


  close(client_sockfd);

  return 0;
};
